package tech.xiaoniu.aspectjandroiddemo

import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.os.Bundle
import android.util.Log
import android.webkit.WebChromeClient
import android.webkit.WebResourceResponse
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.appcompat.app.AppCompatActivity
import tech.xiaoniu.aspect.DebugLog
import kotlin.math.log

class MainActivity : AppCompatActivity() {
    private val TAG = javaClass.simpleName

     lateinit var wv : WebView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        wv = findViewById(R.id.wv)

        setWebView()

//        initView("111111111111111111")
    }

    private fun setWebView() {

        if (wv == null){
            wv = findViewById(R.id.wv)
        }

        var webSet : WebSettings  = wv.settings;
        webSet.javaScriptEnabled = true
        wv.webChromeClient = object : WebChromeClient(){

        }

        wv.webViewClient = object : WebViewClient(){
            @SuppressLint("LongLogTag")
            override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean {
                Log.w("shouldOverrideUrlLoading" , url + "" )
                return super.shouldOverrideUrlLoading(view, url)
            }

            override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) {
//                Log.w("onPageStarted" , url + "" )
                super.onPageStarted(view, url, favicon)
            }

            override fun onPageFinished(view: WebView?, url: String?) {
                Log.w("onPageFinished" , url + "" )
                super.onPageFinished(view, url)
            }

            override fun shouldInterceptRequest(
                view: WebView?,
                url: String?
            ): WebResourceResponse? {
//                Log.w("shouldInterceptRequest" , url + "" )
                return super.shouldInterceptRequest(view, url)
            }
        }
        wv.loadUrl("https://www.baidu.com")

    }

//    @DebugLog
//    fun initView(mm : String) {
//        Log.w("onPageFinished" ,mm )
//    }
}